package com.qf.service.impl;

import com.qf.dao.CarMapper;
import com.qf.dao.UserMapper;
import com.qf.pojo.Car;
import com.qf.service.CarService;
import com.qf.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CarServiceImpl implements CarService {

    @Autowired
    CarMapper carMapper;

    @Override
    public BaseResult findAllByPrice() {
        List<Car> allByPrice = carMapper.findAllByPrice();
        BaseResult baseResult = new BaseResult();
        if(allByPrice==null){
            baseResult.setCode(10000);
            return baseResult;
        }
        baseResult.setCode(1);
        baseResult.setInfo(allByPrice);
        return baseResult;
    }

    @Override
    public BaseResult findAllByHot() {
        List<Car> allByHot = carMapper.findAllByHot();
        BaseResult baseResult = new BaseResult();
        if(allByHot==null){
            baseResult.setCode(10000);
            return baseResult;
        }
        baseResult.setCode(1);
        baseResult.setInfo(allByHot);
        return baseResult;
    }

    @Override
    public BaseResult findCarById(int id) {
        BaseResult baseResult = new BaseResult();
        Car car = carMapper.findCarById(id);
        if(car==null){
            baseResult.setCode(2000);
            return baseResult;
        }
        baseResult.setCode(1);
        baseResult.setInfo(car);
        return baseResult;
    }
}
